package threadcommunication.procucerconsumer.demo_02;


import threadcommunication.procucerconsumer.demo_01.ValueObject;

public class C {
    private String lock;

    public C(String lock) {
        this.lock = lock;
    }

    public void getValue() {
        try {
            synchronized (lock) {
                while (ValueObject.value.equals("")) {
                    System.out.println("consumer" + Thread.currentThread().getName() + "WAITING...");
                    lock.wait();
                }

                System.out.println("consumer" + Thread.currentThread().getName() + "WAITING...");
                ValueObject.value = "";
                lock.notify();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
